home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 14480 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.4 KB

  1. Path: news.compuserve.com!newsmaster
  2. From: 100435.736@compuserve.com (David A. Mair)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Check if a file exists?
  5. Date: Mon, 15 Apr 1996 07:45:19 GMT
  6. Organization: CompuServe Incorporated
  7. Message-ID: <4ksuqi$gls@arl-news-svc-5.compuserve.com>
  8. References: <4kp7pg$upe@news-s01.ny.us.ibm.net>
  9. NNTP-Posting-Host: dd15-052.compuserve.com
  10. X-Newsreader: Forte Free Agent 1.0.82
  11.  
  12. bfilone@ibm.net  <Bruce Filone> wrote:
  13.  
  14. >Is it possible in C to check if a file exists other than checking for a succesful 
  15. >fopen? ON a unix machine, I just want to know if a file is there or not, do not
  16. >to read or write anything to it. similar to the -f test in unix? I was hoping for
  17. >something less costly than opening and closing if exists because I am checking
  18. >for the existance of many files during the run of a process 
  19. >Did not see any postings that seemed to refer to this.
  20. >Thanks in advance. 
  21. >Bruce
  22.  
  23.  
  24. Well, depending on the environment you could open the directory and
  25. search it for the filename.  Some PC based C compilers support an
  26. open_dir() function, it may be supported in other environments but I
  27. only know PCs.  I have never used it but if you are working on a PC
  28. with a mainstream compiler it may help.  There is also the MS-DOS
  29. FindFirst/FindNext operation which reads the directory looking for
  30. something you specify, although clearly this is a MS-DOS function and
  31. not part of the standard C RTL.
  32.  
  33. Regards
  34. David.
  35.  
  36.